package com.wyp168.leetcode;

/**
 * @ClassName MaxScore
 * @Description TODO 计算分割后的最大成绩
 * @Author wyp168
 * @Date 2022/8/20 12:10
 */
public class MaxScore {
    public static void main(String[] args) {
        MaxScore maxScore = new MaxScore();
        String s = "011101";
        System.out.println(maxScore.maxScore(s));
    }
    //分割后分割点左边的0的个数 + 分割点右边的1的个数的最大值
    public int maxScore(String s) {
        int leftZeroCount = 0;
        int rightOneCount = 0;
        for(int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == '1') {
                rightOneCount ++;
            }
        }
        if (s.charAt(0) == '0') {
            leftZeroCount ++;
        }
        int ans = leftZeroCount + rightOneCount;

        for(int i = 1; i < s.length() - 1; i++) {
            if (s.charAt(i) == '0') {
                leftZeroCount ++;
            } else {
                rightOneCount --;
            }
            int temp = leftZeroCount + rightOneCount;
            if (ans < temp) {
                ans = temp;
            }
        }
        return ans;

    }
}
